<template>

<a-card title="餐厨垃圾录接口"  >



  <a-form ref="formRef" :model="formState" layout="vertical" :rules="RULES">
    <a-row :gutter="12">
      <a-col :span="12">
        <a-form-item label="发货单位" field="shippingUnit">
          <a-input v-model="formState.shippingUnit" allow-clear placeholder="请填写发货单位"/>
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="收货单位" field="receivingUnit">
          <a-input v-model="formState.receivingUnit" allow-clear placeholder="请填写收货单位"/>
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="运输单位" field="transportUnit">
          <a-input v-model="formState.transportUnit" allow-clear placeholder="请填写运输单位"/>
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="型号" field="model">
          <a-input v-model="formState.model" allow-clear placeholder="请填写类别编码"/>
        </a-form-item>
      </a-col>

      <a-col :span="8">
        <a-form-item label="毛重" field="grossWeight">
          <a-input-number v-model="formState.grossWeight" :min="0" :step="0.10" mode="embed" placeholder="请填写毛重">
            <template #suffix>
              斤&nbsp;&nbsp;&nbsp;&nbsp;
            </template>
          </a-input-number>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item label="皮重" field="tareWeight">
          <a-input-number v-model="formState.tareWeight" :min="0"  :step="0.10" mode="embed" placeholder="请填写皮重">
            <template #suffix>
              斤&nbsp;&nbsp;&nbsp;&nbsp;
            </template>
          </a-input-number>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item label="净重" field="netWeight">
          <a-input-number v-model="formState.netWeight" :min="0" :step="0.10" mode="embed" @change="uppercase" @input="uppercase" placeholder="请填写净重">
            <template #suffix>
              斤&nbsp;&nbsp;&nbsp;&nbsp;
            </template>
          </a-input-number>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item label="类型名称" field="kindName">
          <a-input v-model="formState.kindName" allow-clear placeholder="请填写类型名称"/>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item label="毛重检斤时间" field="grossTime">
          <a-date-picker showTime style="width: 100%" v-model="formState.grossTime" allow-clear placeholder="请填写毛重检斤时间"/>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item label="大写净重" field="weightInWords">
          <a-input v-model="formState.weightInWords" allow-clear placeholder="请填写大写净重"/>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item label="皮重检斤时间" field="tareTime">
          <a-date-picker style="width: 100%" showTime v-model="formState.tareTime" allow-clear placeholder="请填写皮重检斤时间"/>
        </a-form-item>
      </a-col>

      <a-col :span="8">
        <a-form-item label="上报人" field="reporter">
          <a-input v-model="formState.reporter" allow-clear placeholder="请填写上报人"/>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item label="上报时间" field="reportingTime">
          <a-date-picker style="width: 100%" showTime v-model="formState.reportingTime" allow-clear placeholder="请填写上报时间"/>
        </a-form-item>
      </a-col>

      <a-col>
        <div style="width: 100%; text-align: right; margin-top: 20px">
          <a-button type="primary" @click="onsubmit"> 提交单据</a-button>

        </div>
      </a-col>
    </a-row>
  </a-form>
</a-card>
</template>

<script setup>
import {reactive, ref} from 'vue';
import {Modal, Notification} from '@arco-design/web-vue'
import {AddChefAjax, AddWeighingAjax} from "@/util/AjaxUtil.js";
import FormRuleUtil from "@/util/FormRuleUtil.js";

const formRef = ref(null)

const RULES = {
  model: FormRuleUtil.strRule("型号", true, 500),
  shippingUnit: FormRuleUtil.strRule("发货单位", true, 500),
  receivingUnit: FormRuleUtil.strRule("收货单位", true, 500),
  transportUnit: FormRuleUtil.strRule("运输单位", true, 500),
  kindName: FormRuleUtil.strRule("类名", true, 500),
  grossWeight: FormRuleUtil.numRule("毛重", true, 0,99999),
  tareWeight: FormRuleUtil.numRule("皮重", true, 0,99999),
  netWeight: FormRuleUtil.numRule("净重", true, 0,99999),
  grossTime: FormRuleUtil.strRule("毛重检斤时间", true, 500),
  tareTime: FormRuleUtil.strRule("皮重检斤时间", true, 500),
  weightInWords: FormRuleUtil.strRule("大写净重", true, 500),
  reporter: FormRuleUtil.strRule("上报人", true, 500),
  reportingTime: FormRuleUtil.strRule("上报时间", true, 500)
}

const formState = reactive({
  model: null,
  shippingUnit: null,
  receivingUnit: null,
  transportUnit: null,
  kindName: null,
  grossWeight: 0,
  tareWeight: 0,
  netWeight: 0,
  grossTime: null,
  tareTime: null,
  weightInWords: null,
  reporter: null,
  reportingTime: null
})


const onsubmit = async () => {
  const x = await formRef.value.validate()
  if (x !== undefined) return


  const tips = "确定要提交这个餐厨垃单吗？"
  const handler = async () => {
    const data = await AddWeighingAjax(formState)
    console.log(data)
    setTimeout(() => {
      location.reload()
    },1000)
  }

  Modal.confirm({
    title: '操作提示',
    content: tips,
    okText: '确定提交',
    onOk: () => handler()

  })
}

</script>
